home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / DirectObject.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  2.6 KB  |  123 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DirectObject.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __DIRECTOBJECT__
  15. #include "DirectObject.h"
  16. #endif
  17.  
  18. #ifndef    __DEBUGASSERT__
  19. #include "DebugAssert.h"
  20. #endif
  21.  
  22. #ifndef    __DEBUGGINGGEAR__
  23. #include "DebuggingGear.h"
  24. #endif
  25.  
  26. #ifndef    __IOSTREAM__
  27. #include "IOStream.h"
  28. #endif
  29.  
  30. /***********************************|****************************************/
  31.  
  32. ostream& operator << ( ostream& s, const TDirectObject* o )
  33. {
  34.     if ( o )
  35.         return *o >> s;
  36.     else
  37.         return s << "<NIL>";
  38. }
  39.  
  40. /***********************************|****************************************/
  41.  
  42. TDirectObject::TDirectObject ()
  43. {
  44. #if defined ( debug )
  45.     fTag = kDirectObjectTag;
  46. #endif
  47. }
  48.  
  49. /***********************************|****************************************/
  50.  
  51. TDirectObject::TDirectObject ( const TDirectObject& )
  52. {
  53. #if defined ( debug )
  54.     fTag = kDirectObjectTag;
  55. #endif
  56. }
  57.  
  58. /***********************************|****************************************/
  59.  
  60. TDirectObject::~TDirectObject ()
  61. {
  62.     #if debug
  63.     fTag = '\?\?\?\?';
  64.     #endif
  65. }
  66.  
  67. /***********************************|****************************************/
  68.  
  69. TDirectObject&
  70. TDirectObject::operator = ( const TDirectObject& that )
  71. {
  72.     ASSERT ( this != &that );
  73.     return *this;
  74. }
  75.  
  76. /***********************************|****************************************/
  77.  
  78. ostream&
  79. TDirectObject::operator >> ( ostream& s ) const
  80. {
  81.     s << "TDirectObject @ " << (void*) this;
  82.     return s;
  83. }
  84.  
  85. /***********************************|****************************************/
  86.  
  87. Boolean TDirectObject::IsADirectObject ( const void * p )
  88. {    TDirectObject * t = (TDirectObject *) p;
  89.         
  90.     return t->fTag == kDirectObjectTag;
  91. }
  92.  
  93. /***********************************|****************************************/
  94.  
  95. Boolean TDirectObject::IsValidObject ( Boolean mustReturn ) const
  96. {
  97.     Ptr p = (Ptr) this;
  98.  
  99.     if ( ( (long) p & 0x00000001 ) ||                                //    If the object pointer is odd,
  100.             ( p < (Ptr) & ( ApplicZone()->heapData ) ) ||    //    or below the application zone
  101.             ( p > ApplicZone()->bkLim ) )                    //    or above the application zone
  102.     {
  103.         keith << "TDirectObject::IsValidObject(), bad object pointer." << endl;
  104.     }
  105.     else if ( fTag != kDirectObjectTag )
  106.     {    
  107.         keith << "TDirectObject::IsValidObject(), fTag != kDirectObjectTag." << endl;
  108.     }
  109.     else
  110.     {
  111.         return true;
  112.     }
  113.     
  114.     //    If we get here, the object is bad, so print out a stack crawl,
  115.     //    call Failure() for the current thread, and exit.
  116.     if ( ! mustReturn )
  117.         FAIL ( -1 );
  118.     
  119.     return false;
  120. }
  121.  
  122. /***********************************|****************************************/
  123.